package mappers;

import java.io.IOException;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;

import jobs.ImportInputFile;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import org.apache.log4j.Logger;

public class ImportXMLFileMapper extends Mapper<LongWritable, Text, Text, Text> {
	
	private static final Logger sLogger = Logger.getLogger(ImportInputFile.class);
	
	public void map(LongWritable key, Text valueIn, Context context) throws IOException, InterruptedException {
	 		 
		 // Convert record value Text(xml inside) to String
		 String xmlString = valueIn.toString();  
 
		 // Xml parser
         //SAXBuilder builder = new SAXBuilder();
         //Reader in = new StringReader(xmlString);
          
         // String to emit
         String value="";
         try {       
        	// Build xml Document from record String
	        //Document doc = builder.build(in);
	        //Element root = doc.getRootElement();
	        
	        // Get some values from the Document
	        //String tag1 = root.getName();
	        //String tag2 = tag1;
	        //String tag1 =root.getChild("contact").getChild("name").getTextTrim() ;	      
	        //String tag2 =root.getChild("company").getChild("tag1").getChild("tag2").getTextTrim();
	        //String tag2 =root.getChild("contact").getChild("company").getTextTrim();
	        //value= tag1 + "," + tag2;
	        //value = "aaa";
	        context.write(new Text("AA"), new Text(valueIn));
	    } 
	      //catch (JDOMException ex) {
	        //Logger.getLogger(MyParserMapper.class.getName()).log(Level.SEVERE, null, ex);
	    //} 
	      catch (IOException ex) {
	        //Logger.getLogger(MyParserMapper.class.getName()).log(Level.SEVERE, null, ex);
	    }

	}
		 //context.write(new Text(key.toString()), value);
		 //context.write(key, value);
}
